import { Component, OnInit } from '@angular/core';
import { loginData } from '../date/logindate';
import { LoginServiceService } from '../services/login-service.service';
import { UserInfoService } from '../services/user-info.service';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  constructor(private loginService:LoginServiceService,private userinfo:UserInfoService) { }

  public user:loginData={
    user_name:'',
    user_password:''
  };

  login():void{
    console.log('login');
    console.log(this.user);
    this.loginService.login(this.user).subscribe(
      data=>{
         if(data!=null){
          console.log("登录成功")
          alert("登录成功")
          console.log(data)
          this.userinfo.Setuserinfo(data);
          window.location.href="http://localhost:4200/user"
      }
    }
    );
  }

  signup(){
    window.location.href="http://localhost:4200/register"
  }

  ngOnInit(): void {
  }

}
